﻿using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using LibKetoan;
using LibDuoc;
using System.Reflection;
using System.Runtime.InteropServices;
using Excel;

namespace Ketoan
{
	/// <summary>
	/// Summary description for frmDm.
	/// </summary>
	public class frmDmnv : System.Windows.Forms.Form
	{
        private LibDuoc.AccessData s = new LibDuoc.AccessData();
		private System.Windows.Forms.DataGrid dataGrid1;
		private System.Windows.Forms.Button butKetthuc;
		private LibKetoan.AccessData a;
		private System.Data.DataTable dt=new System.Data.DataTable();
		private System.Data.DataTable dtk=new System.Data.DataTable();
		private System.Windows.Forms.Button butMoi;
		private System.Windows.Forms.Button butSua;
		private System.Windows.Forms.Button butLuu;
		private System.Windows.Forms.Button butBoqua;
		private System.Windows.Forms.Button butHuy;
		private long l_id;
		private int i_userid;
		private string s_mmyy,sql,medi;
		private System.Windows.Forms.TextBox ma;
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.TextBox tim;
		Excel.Application oxl;
		Excel._Workbook owb;
		Excel._Worksheet osheet;
		private System.Windows.Forms.Label label6;
		private System.Windows.Forms.Label label7;
		private System.Windows.Forms.TextBox ten;
		private System.Windows.Forms.Label label2;
		private System.Windows.Forms.TextBox diachi;
		private System.Windows.Forms.Label label3;
		private System.Windows.Forms.TextBox dienthoai;
		private System.Windows.Forms.Label label4;
		private System.Windows.Forms.Label label8;
		private System.Windows.Forms.Label label9;
		private System.Windows.Forms.TextBox masothue;
		private System.Windows.Forms.TextBox sotaikhoan;
		private System.Windows.Forms.TextBox nganhang;
		private System.Windows.Forms.NumericUpDown stt;
		private System.Windows.Forms.Label label11;
		private System.Windows.Forms.Label label12;
		private System.Windows.Forms.TextBox socmnd;
		private System.Windows.Forms.Label label13;
		private MaskedBox.MaskedBox capngay;
		private System.Windows.Forms.Label label14;
		private System.Windows.Forms.TextBox noicap;
		private System.Windows.Forms.CheckBox chkKho;
		private LibList.List listKho;
		private System.Windows.Forms.CheckBox hide;
		private System.Windows.Forms.TextBox medisoft;
		private System.Windows.Forms.Label label5;
		private System.Windows.Forms.ComboBox makp;
		private System.Windows.Forms.Button butExcel;
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;

		public frmDmnv(LibKetoan.AccessData acc,string mmyy,int userid)
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();
			a=acc;s_mmyy=mmyy;i_userid=userid;
			//
			// TODO: Add any constructor code after InitializeComponent call
			//
		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(frmDmnv));
			this.dataGrid1 = new System.Windows.Forms.DataGrid();
			this.butKetthuc = new System.Windows.Forms.Button();
			this.butMoi = new System.Windows.Forms.Button();
			this.butSua = new System.Windows.Forms.Button();
			this.butLuu = new System.Windows.Forms.Button();
			this.butBoqua = new System.Windows.Forms.Button();
			this.butHuy = new System.Windows.Forms.Button();
			this.ma = new System.Windows.Forms.TextBox();
			this.label1 = new System.Windows.Forms.Label();
			this.tim = new System.Windows.Forms.TextBox();
			this.hide = new System.Windows.Forms.CheckBox();
			this.label6 = new System.Windows.Forms.Label();
			this.listKho = new LibList.List();
			this.medisoft = new System.Windows.Forms.TextBox();
			this.label7 = new System.Windows.Forms.Label();
			this.ten = new System.Windows.Forms.TextBox();
			this.label2 = new System.Windows.Forms.Label();
			this.diachi = new System.Windows.Forms.TextBox();
			this.label3 = new System.Windows.Forms.Label();
			this.dienthoai = new System.Windows.Forms.TextBox();
			this.label4 = new System.Windows.Forms.Label();
			this.label8 = new System.Windows.Forms.Label();
			this.label9 = new System.Windows.Forms.Label();
			this.masothue = new System.Windows.Forms.TextBox();
			this.sotaikhoan = new System.Windows.Forms.TextBox();
			this.nganhang = new System.Windows.Forms.TextBox();
			this.chkKho = new System.Windows.Forms.CheckBox();
			this.stt = new System.Windows.Forms.NumericUpDown();
			this.label11 = new System.Windows.Forms.Label();
			this.label12 = new System.Windows.Forms.Label();
			this.socmnd = new System.Windows.Forms.TextBox();
			this.label13 = new System.Windows.Forms.Label();
			this.capngay = new MaskedBox.MaskedBox();
			this.label14 = new System.Windows.Forms.Label();
			this.noicap = new System.Windows.Forms.TextBox();
			this.label5 = new System.Windows.Forms.Label();
			this.makp = new System.Windows.Forms.ComboBox();
			this.butExcel = new System.Windows.Forms.Button();
			((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.stt)).BeginInit();
			this.SuspendLayout();
			// 
			// dataGrid1
			// 
			this.dataGrid1.AlternatingBackColor = System.Drawing.Color.Lavender;
			this.dataGrid1.Anchor = (((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
				| System.Windows.Forms.AnchorStyles.Left) 
				| System.Windows.Forms.AnchorStyles.Right);
			this.dataGrid1.BackColor = System.Drawing.Color.WhiteSmoke;
			this.dataGrid1.BackgroundColor = System.Drawing.SystemColors.Control;
			this.dataGrid1.BorderStyle = System.Windows.Forms.BorderStyle.None;
			this.dataGrid1.CaptionBackColor = System.Drawing.SystemColors.Control;
			this.dataGrid1.CaptionFont = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.dataGrid1.CaptionForeColor = System.Drawing.Color.MidnightBlue;
			this.dataGrid1.DataMember = "";
			this.dataGrid1.FlatMode = true;
			this.dataGrid1.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.dataGrid1.ForeColor = System.Drawing.Color.MidnightBlue;
			this.dataGrid1.GridLineColor = System.Drawing.Color.Gainsboro;
			this.dataGrid1.GridLineStyle = System.Windows.Forms.DataGridLineStyle.None;
			this.dataGrid1.HeaderFont = new System.Drawing.Font("Tahoma", 8F, System.Drawing.FontStyle.Bold);
			this.dataGrid1.HeaderForeColor = System.Drawing.Color.WhiteSmoke;
			this.dataGrid1.LinkColor = System.Drawing.Color.Teal;
			this.dataGrid1.Location = new System.Drawing.Point(8, 8);
			this.dataGrid1.Name = "dataGrid1";
			this.dataGrid1.ParentRowsBackColor = System.Drawing.Color.Gainsboro;
			this.dataGrid1.ParentRowsForeColor = System.Drawing.Color.MidnightBlue;
			this.dataGrid1.ReadOnly = true;
			this.dataGrid1.RowHeaderWidth = 10;
			this.dataGrid1.SelectionBackColor = System.Drawing.Color.CadetBlue;
			this.dataGrid1.SelectionForeColor = System.Drawing.Color.WhiteSmoke;
			this.dataGrid1.Size = new System.Drawing.Size(776, 368);
			this.dataGrid1.TabIndex = 28;
			this.dataGrid1.CurrentCellChanged += new System.EventHandler(this.dataGrid1_CurrentCellChanged);
			// 
			// butKetthuc
			// 
			this.butKetthuc.Anchor = (System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left);
			this.butKetthuc.Image = ((System.Drawing.Bitmap)(resources.GetObject("butKetthuc.Image")));
			this.butKetthuc.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
			this.butKetthuc.Location = new System.Drawing.Point(547, 504);
			this.butKetthuc.Name = "butKetthuc";
			this.butKetthuc.Size = new System.Drawing.Size(70, 25);
			this.butKetthuc.TabIndex = 21;
			this.butKetthuc.Text = "&Kết thúc";
			this.butKetthuc.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			this.butKetthuc.Click += new System.EventHandler(this.butKetthuc_Click);
			// 
			// butMoi
			// 
			this.butMoi.Anchor = (System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left);
			this.butMoi.Image = ((System.Drawing.Bitmap)(resources.GetObject("butMoi.Image")));
			this.butMoi.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
			this.butMoi.Location = new System.Drawing.Point(175, 504);
			this.butMoi.Name = "butMoi";
			this.butMoi.Size = new System.Drawing.Size(60, 25);
			this.butMoi.TabIndex = 17;
			this.butMoi.Text = "     &Mới";
			this.butMoi.Click += new System.EventHandler(this.butMoi_Click);
			// 
			// butSua
			// 
			this.butSua.Anchor = (System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left);
			this.butSua.Image = ((System.Drawing.Bitmap)(resources.GetObject("butSua.Image")));
			this.butSua.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
			this.butSua.Location = new System.Drawing.Point(237, 504);
			this.butSua.Name = "butSua";
			this.butSua.Size = new System.Drawing.Size(60, 25);
			this.butSua.TabIndex = 18;
			this.butSua.Text = "    &Sửa";
			this.butSua.Click += new System.EventHandler(this.butSua_Click);
			// 
			// butLuu
			// 
			this.butLuu.Anchor = (System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left);
			this.butLuu.Enabled = false;
			this.butLuu.Image = ((System.Drawing.Bitmap)(resources.GetObject("butLuu.Image")));
			this.butLuu.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
			this.butLuu.Location = new System.Drawing.Point(299, 504);
			this.butLuu.Name = "butLuu";
			this.butLuu.Size = new System.Drawing.Size(60, 25);
			this.butLuu.TabIndex = 15;
			this.butLuu.Text = "     &Lưu";
			this.butLuu.Click += new System.EventHandler(this.butLuu_Click);
			// 
			// butBoqua
			// 
			this.butBoqua.Anchor = (System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left);
			this.butBoqua.Enabled = false;
			this.butBoqua.Image = ((System.Drawing.Bitmap)(resources.GetObject("butBoqua.Image")));
			this.butBoqua.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
			this.butBoqua.Location = new System.Drawing.Point(361, 504);
			this.butBoqua.Name = "butBoqua";
			this.butBoqua.Size = new System.Drawing.Size(60, 25);
			this.butBoqua.TabIndex = 16;
			this.butBoqua.Text = "&Bỏ qua";
			this.butBoqua.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			this.butBoqua.Click += new System.EventHandler(this.butBoqua_Click);
			// 
			// butHuy
			// 
			this.butHuy.Anchor = (System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left);
			this.butHuy.Image = ((System.Drawing.Bitmap)(resources.GetObject("butHuy.Image")));
			this.butHuy.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
			this.butHuy.Location = new System.Drawing.Point(485, 504);
			this.butHuy.Name = "butHuy";
			this.butHuy.Size = new System.Drawing.Size(60, 25);
			this.butHuy.TabIndex = 20;
			this.butHuy.Text = "    &Hủy";
			this.butHuy.Click += new System.EventHandler(this.butHuy_Click);
			// 
			// ma
			// 
			this.ma.Anchor = (System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left);
			this.ma.BackColor = System.Drawing.SystemColors.HighlightText;
			this.ma.CharacterCasing = System.Windows.Forms.CharacterCasing.Upper;
			this.ma.Enabled = false;
			this.ma.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.ma.Location = new System.Drawing.Point(144, 403);
			this.ma.MaxLength = 20;
			this.ma.Name = "ma";
			this.ma.Size = new System.Drawing.Size(104, 21);
			this.ma.TabIndex = 2;
			this.ma.Text = "";
			this.ma.KeyDown += new System.Windows.Forms.KeyEventHandler(this.stt_KeyDown);
			this.ma.Validated += new System.EventHandler(this.ma_Validated);
			// 
			// label1
			// 
			this.label1.Anchor = (System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left);
			this.label1.Location = new System.Drawing.Point(248, 403);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(32, 23);
			this.label1.TabIndex = 0;
			this.label1.Text = "Tên :";
			this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			// 
			// tim
			// 
			this.tim.Anchor = ((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
				| System.Windows.Forms.AnchorStyles.Right);
			this.tim.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.tim.Location = new System.Drawing.Point(8, 5);
			this.tim.Name = "tim";
			this.tim.Size = new System.Drawing.Size(776, 21);
			this.tim.TabIndex = 29;
			this.tim.Text = "Tìm kiếm";
			this.tim.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
			this.tim.TextChanged += new System.EventHandler(this.tim_TextChanged);
			this.tim.Enter += new System.EventHandler(this.tim_Enter);
			// 
			// hide
			// 
			this.hide.Anchor = (System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right);
			this.hide.Enabled = false;
			this.hide.Location = new System.Drawing.Point(640, 498);
			this.hide.Name = "hide";
			this.hide.Size = new System.Drawing.Size(128, 16);
			this.hide.TabIndex = 22;
			this.hide.Text = "Không sử dụng nữa";
			this.hide.KeyDown += new System.Windows.Forms.KeyEventHandler(this.stt_KeyDown);
			// 
			// label6
			// 
			this.label6.Anchor = (System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left);
			this.label6.Location = new System.Drawing.Point(96, 403);
			this.label6.Name = "label6";
			this.label6.Size = new System.Drawing.Size(48, 23);
			this.label6.TabIndex = 30;
			this.label6.Text = "Mã :";
			this.label6.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			// 
			// listKho
			// 
			this.listKho.Anchor = (System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left);
			this.listKho.BackColor = System.Drawing.SystemColors.Info;
			this.listKho.ColumnCount = 0;
			this.listKho.Location = new System.Drawing.Point(489, 544);
			this.listKho.MatchBufferTimeOut = 1000;
			this.listKho.MatchEntryStyle = AsYetUnnamed.MatchEntryStyle.FirstLetterInsensitive;
			this.listKho.Name = "listKho";
			this.listKho.Size = new System.Drawing.Size(75, 17);
			this.listKho.TabIndex = 33;
			this.listKho.TextIndex = -1;
			this.listKho.TextMember = null;
			this.listKho.ValueIndex = -1;
			this.listKho.Visible = false;
			this.listKho.KeyDown += new System.Windows.Forms.KeyEventHandler(this.listKho_KeyDown);
			// 
			// medisoft
			// 
			this.medisoft.Anchor = ((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left) 
				| System.Windows.Forms.AnchorStyles.Right);
			this.medisoft.BackColor = System.Drawing.SystemColors.HighlightText;
			this.medisoft.Enabled = false;
			this.medisoft.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.medisoft.Location = new System.Drawing.Point(64, 379);
			this.medisoft.Name = "medisoft";
			this.medisoft.Size = new System.Drawing.Size(720, 21);
			this.medisoft.TabIndex = 0;
			this.medisoft.Text = "";
			this.medisoft.KeyDown += new System.Windows.Forms.KeyEventHandler(this.medisoft_KeyDown);
			this.medisoft.Validated += new System.EventHandler(this.medisoft_Validated);
			this.medisoft.TextChanged += new System.EventHandler(this.medisoft_TextChanged);
			// 
			// label7
			// 
			this.label7.Anchor = (System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left);
			this.label7.Location = new System.Drawing.Point(8, 379);
			this.label7.Name = "label7";
			this.label7.Size = new System.Drawing.Size(56, 23);
			this.label7.TabIndex = 32;
			this.label7.Text = "Medisoft :";
			this.label7.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			// 
			// ten
			// 
			this.ten.Anchor = ((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left) 
				| System.Windows.Forms.AnchorStyles.Right);
			this.ten.BackColor = System.Drawing.SystemColors.HighlightText;
			this.ten.Enabled = false;
			this.ten.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.ten.Location = new System.Drawing.Point(280, 403);
			this.ten.Name = "ten";
			this.ten.Size = new System.Drawing.Size(296, 21);
			this.ten.TabIndex = 3;
			this.ten.Text = "";
			this.ten.KeyDown += new System.Windows.Forms.KeyEventHandler(this.stt_KeyDown);
			this.ten.Validated += new System.EventHandler(this.ten_Validated);
			// 
			// label2
			// 
			this.label2.Anchor = (System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left);
			this.label2.Location = new System.Drawing.Point(0, 427);
			this.label2.Name = "label2";
			this.label2.Size = new System.Drawing.Size(64, 23);
			this.label2.TabIndex = 35;
			this.label2.Text = "Địa chỉ :";
			this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			// 
			// diachi
			// 
			this.diachi.Anchor = ((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left) 
				| System.Windows.Forms.AnchorStyles.Right);
			this.diachi.BackColor = System.Drawing.SystemColors.HighlightText;
			this.diachi.Enabled = false;
			this.diachi.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.diachi.Location = new System.Drawing.Point(64, 427);
			this.diachi.Name = "diachi";
			this.diachi.Size = new System.Drawing.Size(512, 21);
			this.diachi.TabIndex = 5;
			this.diachi.Text = "";
			this.diachi.KeyDown += new System.Windows.Forms.KeyEventHandler(this.stt_KeyDown);
			// 
			// label3
			// 
			this.label3.Anchor = (System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right);
			this.label3.Location = new System.Drawing.Point(576, 427);
			this.label3.Name = "label3";
			this.label3.Size = new System.Drawing.Size(64, 23);
			this.label3.TabIndex = 37;
			this.label3.Text = "Điện thoại :";
			this.label3.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			// 
			// dienthoai
			// 
			this.dienthoai.Anchor = (System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right);
			this.dienthoai.BackColor = System.Drawing.SystemColors.HighlightText;
			this.dienthoai.Enabled = false;
			this.dienthoai.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.dienthoai.Location = new System.Drawing.Point(640, 427);
			this.dienthoai.MaxLength = 20;
			this.dienthoai.Name = "dienthoai";
			this.dienthoai.Size = new System.Drawing.Size(144, 21);
			this.dienthoai.TabIndex = 6;
			this.dienthoai.Text = "";
			this.dienthoai.KeyDown += new System.Windows.Forms.KeyEventHandler(this.stt_KeyDown);
			// 
			// label4
			// 
			this.label4.Anchor = (System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left);
			this.label4.Location = new System.Drawing.Point(-8, 452);
			this.label4.Name = "label4";
			this.label4.Size = new System.Drawing.Size(72, 23);
			this.label4.TabIndex = 39;
			this.label4.Text = "Mã số thuế :";
			this.label4.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			// 
			// label8
			// 
			this.label8.Anchor = (System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left);
			this.label8.Location = new System.Drawing.Point(200, 452);
			this.label8.Name = "label8";
			this.label8.Size = new System.Drawing.Size(80, 23);
			this.label8.TabIndex = 40;
			this.label8.Text = "Số tài khoản :";
			this.label8.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			// 
			// label9
			// 
			this.label9.Anchor = (System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left);
			this.label9.Location = new System.Drawing.Point(416, 452);
			this.label9.Name = "label9";
			this.label9.Size = new System.Drawing.Size(80, 23);
			this.label9.TabIndex = 41;
			this.label9.Text = "Ngân hàng :";
			this.label9.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			// 
			// masothue
			// 
			this.masothue.Anchor = (System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left);
			this.masothue.BackColor = System.Drawing.SystemColors.HighlightText;
			this.masothue.Enabled = false;
			this.masothue.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.masothue.Location = new System.Drawing.Point(64, 451);
			this.masothue.Name = "masothue";
			this.masothue.Size = new System.Drawing.Size(144, 21);
			this.masothue.TabIndex = 7;
			this.masothue.Text = "";
			this.masothue.KeyDown += new System.Windows.Forms.KeyEventHandler(this.stt_KeyDown);
			// 
			// sotaikhoan
			// 
			this.sotaikhoan.Anchor = (System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left);
			this.sotaikhoan.BackColor = System.Drawing.SystemColors.HighlightText;
			this.sotaikhoan.Enabled = false;
			this.sotaikhoan.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.sotaikhoan.Location = new System.Drawing.Point(280, 451);
			this.sotaikhoan.Name = "sotaikhoan";
			this.sotaikhoan.Size = new System.Drawing.Size(150, 21);
			this.sotaikhoan.TabIndex = 8;
			this.sotaikhoan.Text = "";
			this.sotaikhoan.KeyDown += new System.Windows.Forms.KeyEventHandler(this.stt_KeyDown);
			// 
			// nganhang
			// 
			this.nganhang.Anchor = ((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left) 
				| System.Windows.Forms.AnchorStyles.Right);
			this.nganhang.BackColor = System.Drawing.SystemColors.HighlightText;
			this.nganhang.Enabled = false;
			this.nganhang.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.nganhang.Location = new System.Drawing.Point(496, 451);
			this.nganhang.Name = "nganhang";
			this.nganhang.Size = new System.Drawing.Size(288, 21);
			this.nganhang.TabIndex = 9;
			this.nganhang.Text = "";
			this.nganhang.KeyDown += new System.Windows.Forms.KeyEventHandler(this.stt_KeyDown);
			// 
			// chkKho
			// 
			this.chkKho.Anchor = (System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right);
			this.chkKho.Location = new System.Drawing.Point(640, 514);
			this.chkKho.Name = "chkKho";
			this.chkKho.Size = new System.Drawing.Size(136, 16);
			this.chkKho.TabIndex = 23;
			this.chkKho.Text = "Danh mục Medisoft";
			this.chkKho.CheckedChanged += new System.EventHandler(this.chkKho_CheckedChanged);
			// 
			// stt
			// 
			this.stt.Anchor = (System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left);
			this.stt.BackColor = System.Drawing.SystemColors.HighlightText;
			this.stt.Enabled = false;
			this.stt.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.stt.Location = new System.Drawing.Point(64, 403);
			this.stt.Maximum = new System.Decimal(new int[] {
																9999999,
																0,
																0,
																0});
			this.stt.Name = "stt";
			this.stt.Size = new System.Drawing.Size(56, 21);
			this.stt.TabIndex = 1;
			this.stt.KeyDown += new System.Windows.Forms.KeyEventHandler(this.stt_KeyDown);
			// 
			// label11
			// 
			this.label11.Anchor = (System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left);
			this.label11.Location = new System.Drawing.Point(16, 403);
			this.label11.Name = "label11";
			this.label11.Size = new System.Drawing.Size(48, 23);
			this.label11.TabIndex = 49;
			this.label11.Text = "Số TT :";
			this.label11.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			// 
			// label12
			// 
			this.label12.Anchor = (System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left);
			this.label12.Location = new System.Drawing.Point(-16, 474);
			this.label12.Name = "label12";
			this.label12.Size = new System.Drawing.Size(80, 23);
			this.label12.TabIndex = 50;
			this.label12.Text = "Số CMND :";
			this.label12.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			// 
			// socmnd
			// 
			this.socmnd.Anchor = (System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left);
			this.socmnd.BackColor = System.Drawing.SystemColors.HighlightText;
			this.socmnd.Enabled = false;
			this.socmnd.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.socmnd.Location = new System.Drawing.Point(64, 474);
			this.socmnd.Name = "socmnd";
			this.socmnd.Size = new System.Drawing.Size(144, 21);
			this.socmnd.TabIndex = 11;
			this.socmnd.Text = "";
			this.socmnd.KeyDown += new System.Windows.Forms.KeyEventHandler(this.stt_KeyDown);
			// 
			// label13
			// 
			this.label13.Anchor = (System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left);
			this.label13.Location = new System.Drawing.Point(200, 474);
			this.label13.Name = "label13";
			this.label13.Size = new System.Drawing.Size(80, 23);
			this.label13.TabIndex = 52;
			this.label13.Text = "Cấp ngày :";
			this.label13.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			// 
			// capngay
			// 
			this.capngay.Anchor = (System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left);
			this.capngay.BackColor = System.Drawing.SystemColors.HighlightText;
			this.capngay.Enabled = false;
			this.capngay.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.capngay.Location = new System.Drawing.Point(280, 474);
			this.capngay.Mask = "##/##/####";
			this.capngay.MaxLength = 10;
			this.capngay.Name = "capngay";
			this.capngay.Size = new System.Drawing.Size(64, 21);
			this.capngay.TabIndex = 12;
			this.capngay.Text = "";
			this.capngay.KeyDown += new System.Windows.Forms.KeyEventHandler(this.stt_KeyDown);
			this.capngay.Validated += new System.EventHandler(this.capngay_Validated);
			// 
			// label14
			// 
			this.label14.Anchor = (System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left);
			this.label14.Location = new System.Drawing.Point(424, 472);
			this.label14.Name = "label14";
			this.label14.Size = new System.Drawing.Size(72, 23);
			this.label14.TabIndex = 54;
			this.label14.Text = "Nơi cấp :";
			this.label14.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			// 
			// noicap
			// 
			this.noicap.Anchor = ((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left) 
				| System.Windows.Forms.AnchorStyles.Right);
			this.noicap.BackColor = System.Drawing.SystemColors.HighlightText;
			this.noicap.Enabled = false;
			this.noicap.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.noicap.Location = new System.Drawing.Point(496, 474);
			this.noicap.Name = "noicap";
			this.noicap.Size = new System.Drawing.Size(288, 21);
			this.noicap.TabIndex = 13;
			this.noicap.Text = "";
			this.noicap.KeyDown += new System.Windows.Forms.KeyEventHandler(this.stt_KeyDown);
			// 
			// label5
			// 
			this.label5.Anchor = (System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right);
			this.label5.Location = new System.Drawing.Point(576, 400);
			this.label5.Name = "label5";
			this.label5.Size = new System.Drawing.Size(64, 23);
			this.label5.TabIndex = 55;
			this.label5.Text = "Bộ phận :";
			this.label5.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			// 
			// makp
			// 
			this.makp.Anchor = (System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right);
			this.makp.BackColor = System.Drawing.SystemColors.HighlightText;
			this.makp.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
			this.makp.Enabled = false;
			this.makp.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.makp.Location = new System.Drawing.Point(640, 403);
			this.makp.Name = "makp";
			this.makp.Size = new System.Drawing.Size(144, 21);
			this.makp.TabIndex = 4;
			this.makp.KeyDown += new System.Windows.Forms.KeyEventHandler(this.stt_KeyDown);
			// 
			// butExcel
			// 
			this.butExcel.Anchor = (System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left);
			this.butExcel.Image = ((System.Drawing.Bitmap)(resources.GetObject("butExcel.Image")));
			this.butExcel.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
			this.butExcel.Location = new System.Drawing.Point(424, 504);
			this.butExcel.Name = "butExcel";
			this.butExcel.Size = new System.Drawing.Size(60, 25);
			this.butExcel.TabIndex = 88;
			this.butExcel.Text = "      &In";
			this.butExcel.Click += new System.EventHandler(this.butExcel_Click);
			// 
			// frmDmnv
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(792, 573);
			this.Controls.AddRange(new System.Windows.Forms.Control[] {
																		  this.butExcel,
																		  this.makp,
																		  this.label5,
																		  this.noicap,
																		  this.label14,
																		  this.socmnd,
																		  this.capngay,
																		  this.label13,
																		  this.label12,
																		  this.label11,
																		  this.stt,
																		  this.chkKho,
																		  this.nganhang,
																		  this.sotaikhoan,
																		  this.masothue,
																		  this.label9,
																		  this.label8,
																		  this.label4,
																		  this.dienthoai,
																		  this.label3,
																		  this.diachi,
																		  this.label2,
																		  this.ten,
																		  this.listKho,
																		  this.medisoft,
																		  this.label7,
																		  this.label6,
																		  this.hide,
																		  this.tim,
																		  this.ma,
																		  this.label1,
																		  this.butHuy,
																		  this.butBoqua,
																		  this.butLuu,
																		  this.butSua,
																		  this.butMoi,
																		  this.butKetthuc,
																		  this.dataGrid1});
			this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
			this.Name = "frmDmnv";
			this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
			this.Text = "Danh mục nhân viên";
			this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
			this.KeyDown += new System.Windows.Forms.KeyEventHandler(this.frmDmnv_KeyDown);
			this.Load += new System.EventHandler(this.frmDmnv_Load);
			((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.stt)).EndInit();
			this.ResumeLayout(false);

		}
		#endregion

		private void frmDmnv_Load(object sender, System.EventArgs e)
		{
			makp.DisplayMember="TENKP";
			makp.ValueMember="ID";
			makp.DataSource=a.get_data("select * from a_btdkp order by stt").Tables[0];

			dtk=a.get_data("select hoten,hoten as ten,ma from "+s.user+".dmbs order by ma").Tables[0];
			listKho.DisplayMember = "ten";
			listKho.ValueMember = "ten";
			listKho.DataSource = dtk;

			load_grid();
			AddGridTableStyle();
			ref_text();
			chkKho.Checked=a.Thongso("dmdtmedisoft")=="1";
		}		

		private void load_grid()
		{
			sql="select a.*,to_char(a.capngay,'dd/mm/yyyy') as ngay,b.hoten ";
			sql+=" from a_dmdt a, "+s.user+".dmbs b ";
			sql+=" where a.medisoft=b.ma(+) and a.loaidt=0 order by a.stt";
			dt=a.get_data(sql).Tables[0];
			dataGrid1.DataSource=dt;
		}

		private void AddGridTableStyle()
		{
			DataGridTableStyle ts =new DataGridTableStyle();
			ts.MappingName = dt.TableName;
			ts.AlternatingBackColor = Color.Beige;
			ts.BackColor = Color.GhostWhite;
			ts.ForeColor = Color.MidnightBlue;
			ts.GridLineColor = Color.RoyalBlue;
			ts.HeaderBackColor = Color.MidnightBlue;
			ts.HeaderForeColor = Color.Lavender;
			ts.SelectionBackColor = Color.Teal;
			ts.SelectionForeColor = Color.PaleGreen;
			ts.ReadOnly=false;
			ts.RowHeaderWidth=10;
						
			DataGridTextBoxColumn TextCol=new DataGridTextBoxColumn();
			TextCol.MappingName = "id";
			TextCol.HeaderText = "";
			TextCol.Width = 0;
			ts.GridColumnStyles.Add(TextCol);
			dataGrid1.TableStyles.Add(ts);

			TextCol=new DataGridTextBoxColumn();
			TextCol.MappingName = "stt";
			TextCol.HeaderText = "STT";
			TextCol.Width = 30;
			ts.GridColumnStyles.Add(TextCol);
			dataGrid1.TableStyles.Add(ts);

			TextCol=new DataGridTextBoxColumn();
			TextCol.MappingName = "mavt";
			TextCol.HeaderText = "Mã số";
			TextCol.Width = 80;
			ts.GridColumnStyles.Add(TextCol);
			dataGrid1.TableStyles.Add(ts);

			TextCol=new DataGridTextBoxColumn();
			TextCol.MappingName = "tendt";
			TextCol.HeaderText = "Tên";
			TextCol.Width = 250;
			ts.GridColumnStyles.Add(TextCol);
			dataGrid1.TableStyles.Add(ts);

			TextCol=new DataGridTextBoxColumn();
			TextCol.MappingName = "diachi";
			TextCol.HeaderText = "Địa chỉ";
			TextCol.Width = 300;
			ts.GridColumnStyles.Add(TextCol);
			dataGrid1.TableStyles.Add(ts);

			TextCol=new DataGridTextBoxColumn();
			TextCol.MappingName = "masothue";
			TextCol.HeaderText = "Mã số thuế";
			TextCol.Width = 100;
			ts.GridColumnStyles.Add(TextCol);
			dataGrid1.TableStyles.Add(ts);

			TextCol=new DataGridTextBoxColumn();
			TextCol.MappingName = "sotaikhoan";
			TextCol.HeaderText = "Số tài khoản";
			TextCol.Width = 100;
			ts.GridColumnStyles.Add(TextCol);
			dataGrid1.TableStyles.Add(ts);

			TextCol=new DataGridTextBoxColumn();
			TextCol.MappingName = "nganhang";
			TextCol.HeaderText = "Ngân hàng";
			TextCol.Width = 150;
			ts.GridColumnStyles.Add(TextCol);
			dataGrid1.TableStyles.Add(ts);
		}

		private void butKetthuc_Click(object sender, System.EventArgs e)
		{
			this.Close();
		}

		private void ena_object(bool ena)
		{
			dataGrid1.Enabled=!ena;
			if (chkKho.Checked) medisoft.Enabled=ena;
			ma.Enabled=ten.Enabled=ena;
			tim.Enabled=!ena;
			stt.Enabled=diachi.Enabled=dienthoai.Enabled=masothue.Enabled=sotaikhoan.Enabled=nganhang.Enabled=ena;
			makp.Enabled=socmnd.Enabled=capngay.Enabled=noicap.Enabled=hide.Enabled=ena;
			butMoi.Enabled=!ena;
			butSua.Enabled=!ena;
			butLuu.Enabled=ena;
			butBoqua.Enabled=ena;
			butExcel.Enabled=!ena;
			butHuy.Enabled=!ena;
			butKetthuc.Enabled=!ena;
		}

		private void butMoi_Click(object sender, System.EventArgs e)
		{
			l_id=0;
			try
			{
				stt.Value=decimal.Parse(a.get_data("select max(stt) from a_dmdt where loaidt=0").Tables[0].Rows[0][0].ToString())+1;
			}
			catch{stt.Value=1;}
			medi=medisoft.Text=ma.Text=ten.Text="";
			diachi.Text=dienthoai.Text=masothue.Text=sotaikhoan.Text=nganhang.Text=socmnd.Text=capngay.Text=noicap.Text="";
			hide.Checked=false;
			ena_object(true);
			if (chkKho.Checked) medisoft.Focus();
			else stt.Focus();
		}

		private void butSua_Click(object sender, System.EventArgs e)
		{
			if (dt.Rows.Count==0) return;
			l_id=long.Parse(dataGrid1[dataGrid1.CurrentCell.RowNumber,0].ToString());
			ena_object(true);
			stt.Focus();
		}

		private bool kiemtra()
		{
			if (ma.Text=="")
			{
				ma.Focus();
				return false;
			}
			if (ten.Text=="")
			{
				ten.Focus();
				return false;
			}
			return true;
		}

		private void butLuu_Click(object sender, System.EventArgs e)
		{
			if (!kiemtra()) return ;
			bool bNew=l_id==0;
			l_id=(l_id==0)?a.getIddmdt():l_id;
			if (!a.upd_dmdt(l_id,stt.Value,ten.Text,(makp.SelectedIndex!=-1)?int.Parse(makp.SelectedValue.ToString()):0,0,diachi.Text,dienthoai.Text,"","",masothue.Text,sotaikhoan.Text,nganhang.Text,"","","","",socmnd.Text,capngay.Text,noicap.Text,ma.Text,(hide.Checked)?0:1,medi,"",0,i_userid))
			{
				MessageBox.Show("Không cập nhật thông tin "+this.Text.Trim()+" !",a.Msg);
				return;
			}
			load_grid();
			ref_text();
			ena_object(false);
			butMoi.Focus();
		}

		private void butBoqua_Click(object sender, System.EventArgs e)
		{
			ref_text();
			ena_object(false);
			butMoi.Focus();
		}

		private void butHuy_Click(object sender, System.EventArgs e)
		{
			try
			{
				if (a.get_data("select * from a_sd"+s_mmyy.Substring(2,2)+" where madt="+long.Parse(dataGrid1[dataGrid1.CurrentCell.RowNumber,0].ToString())).Tables[0].Rows.Count!=0)
				{
					MessageBox.Show("Tên "+ten.Text+" đang sử dụng không cho phép hủy !",a.Msg);
					return;
				}
			}
			catch{}
			if (MessageBox.Show("Đồng ý hủy thông tin này !",a.Msg,MessageBoxButtons.YesNo,MessageBoxIcon.Question)==DialogResult.Yes)
			{
				a.execute_data("delete from a_dmdt where id="+long.Parse(dataGrid1[dataGrid1.CurrentCell.RowNumber,0].ToString()));
				load_grid();
			}
		}

		private void ref_text()
		{
			try
			{
				int i=dataGrid1.CurrentCell.RowNumber;
				l_id=long.Parse(dataGrid1[i,0].ToString());
				DataRow r=a.getrowbyid(dt,"id="+l_id);
				if (r!=null)
				{
					stt.Value=decimal.Parse(r["stt"].ToString());
					ma.Text=r["mavt"].ToString();
					ten.Text=r["tendt"].ToString();					
					diachi.Text=r["diachi"].ToString();
					dienthoai.Text=r["dienthoai"].ToString();
					masothue.Text=r["masothue"].ToString();
					sotaikhoan.Text=r["sotaikhoan"].ToString();
					socmnd.Text=r["socmnd"].ToString();
					capngay.Text=r["ngay"].ToString();
					noicap.Text=r["noicap"].ToString();
					medi=r["medisoft"].ToString();
					hide.Checked=r["sudung"].ToString()=="0";
					medisoft.Text=r["hoten"].ToString();
					makp.SelectedValue=r["makp"].ToString();
				}
			}
			catch{}
		}

		private void dataGrid1_CurrentCellChanged(object sender, System.EventArgs e)
		{
			ref_text();
		}

		private void frmDmnv_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
		{
			if (e.KeyCode==Keys.F10) butKetthuc_Click(sender,e);
		}

		private void stt_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
		{
			if (e.KeyCode==Keys.Enter) SendKeys.Send("{Tab}");		
		}

		private void ma_Validated(object sender, System.EventArgs e)
		{
			if (ma.Text!="" && l_id==0)
			{
				DataRow r1=a.getrowbyid(dt,"mavt='"+ma.Text+"'");
				if (r1!=null)
				{
					MessageBox.Show("Mã số đã nhập !",a.Msg);
					ma.Focus();
					return;
				}
				if (ten.Text=="") ten.Text=ma.Text;
			}
		}

		private void ten_Validated(object sender, System.EventArgs e)
		{
			if (l_id==0 && ten.Text!="")
			{
				DataRow r1=a.getrowbyid(dt,"tendt='"+ten.Text+"'");
				if (r1!=null)
				{
					MessageBox.Show("Tên đã nhập !",a.Msg);
					ten.Focus();
				}
			}
		}

		private void RefreshChildren(string text)
		{
			try
			{
				CurrencyManager cm= (CurrencyManager)BindingContext[dataGrid1.DataSource];
				DataView dv=(DataView)cm.List;
				sql="mavt like '%"+text.Trim()+"%' or tendt like '%"+text.Trim()+"%' or masothue like '%"+text.Trim()+"%' or sotaikhoan like '%"+text.Trim()+"%'";
				dv.RowFilter=sql;
				ref_text();
			}
			catch{}
		}

		private void tim_TextChanged(object sender, System.EventArgs e)
		{
			if (this.ActiveControl==tim) RefreshChildren(tim.Text);
		}

		private void tim_Enter(object sender, System.EventArgs e)
		{
			tim.Text="";
		}

		private void butExcel_Click(object sender, System.EventArgs e)
		{
			DataSet _DataSet =new DataSet();
			_DataSet=a._rdanhmucnhanvien(tim.Text);
			frmReport _frmReport =new frmReport(a,_DataSet,"11","KT_rdanhmucnhanvien.rpt");
			_frmReport.ShowDialog();
//			a.check_process_Excel();
//			string tenfile=a.Export_Excel(dt,"dmnv");
//			oxl=new Excel.Application();
//			owb=(Excel._Workbook)(oxl.Workbooks.Open(tenfile,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value));
//			osheet=(Excel._Worksheet)owb.ActiveSheet;
//			oxl.ActiveWindow.DisplayGridlines=true;
//			oxl.ActiveWindow.DisplayZeros=false;
//			osheet.PageSetup.Orientation=XlPageOrientation.xlLandscape;
//			osheet.PageSetup.PaperSize=XlPaperSize.xlPaperA4;
//			osheet.PageSetup.LeftMargin=20;
//			osheet.PageSetup.RightMargin=20;
//			osheet.PageSetup.TopMargin=30;
//			osheet.PageSetup.CenterFooter="Trang : &P/&N";
//			osheet.get_Range("A2","A2").Select();
//			oxl.ActiveWindow.FreezePanes = true;
//			oxl.Visible=true;
		}

		private void chkKho_CheckedChanged(object sender, System.EventArgs e)
		{
			if (this.ActiveControl==chkKho)
			{
				medisoft.Enabled = chkKho.Checked && butLuu.Enabled;
				a.writeXml("a_thongso","dmdtmedisoft",(chkKho.Checked)?"1":"0");
			}
		}

		private void medisoft_TextChanged(object sender, System.EventArgs e)
		{
			if (this.ActiveControl == medisoft)
			{
				Filter(medisoft.Text, listKho);
				listKho.BrowseToDanhmuc(medisoft,medisoft,stt);
			}
		}

		private void Filter(string ten, LibList.List list)
		{
			try
			{
				CurrencyManager cm = (CurrencyManager)BindingContext[list.DataSource];
				DataView dv = (DataView)cm.List;
				dv.RowFilter = "ten like '%" + ten.Trim() + "%'";
			}
			catch { }
		}

		private void medisoft_KeyDown(object sender, KeyEventArgs e)
		{
			if (e.KeyCode == Keys.Down || e.KeyCode == Keys.Up) listKho.Focus();
			else if (e.KeyCode == Keys.Enter)
			{
				if (listKho.Visible) listKho.Focus();
				else SendKeys.Send("{Tab}");
			}
		}

		private void medisoft_Validated(object sender, EventArgs e)
		{
			if (!listKho.Focused) listKho.Hide();
			DataRow r = a.getrowbyid(dtk, "ten='" + medisoft.Text + "'");
			if (r != null && ten.Text == "")
			{				
				ten.Text = r["ten"].ToString();
				medi=ma.Text = r["ma"].ToString();
			}
		}

		private void listKho_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
		{
			if (e.KeyCode == Keys.Enter || e.KeyCode == Keys.Tab) medisoft_Validated(sender, e);
		}

		private void capngay_Validated(object sender, System.EventArgs e)
		{
			if (capngay.Text=="") return;
			capngay.Text=capngay.Text.Trim();
			if (!a.bNgay(capngay.Text))
			{
				MessageBox.Show("Ngày không hợp lệ !",a.Msg);
				capngay.Focus();
				return;
			}
			capngay.Text=a.Ktngaygio(capngay.Text,10);
		}
	}
}
